package com.example.springbootmybatis.exception;

import com.example.springbootmybatis.entity.ResultMap;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
        /**
     * 处理空指针的异常
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value = DataIntegrityViolationException.class)
    public ResultMap exceptionHandler( DataIntegrityViolationException e){
        log.error("发生空指针异常！原因是:",e);
        return BaseResultUtils.error(ResponseEnum.ERROR5);
    }

    @ExceptionHandler(value =Exception.class)
    public ResultMap exceptionHandler( Exception e){
        log.error("发生空指针异常！原因是:",e);
        return BaseResultUtils.error(ResponseEnum.ERROR9999);
    }
}